/**
 * @(#)SellerController.java, 2018/2/8.
 * <p/>
 * Copyright 2018 Kerr Wang, Inc. All rights reserved.
 * KERRWANG PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
 */
package org.wangzx.exercise.controller;

import com.alibaba.fastjson.JSON;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;
import org.wangzx.exercise.enums.LoginType;
import org.wangzx.exercise.exception.CommonServiceException;
import org.wangzx.exercise.meta.vo.UserVO;
import org.wangzx.exercise.utils.LoginUtils;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * @author hzwangzuxiang(ahscwzx@163.com)
 */
@Controller
@RequestMapping("/")
public class SellerController extends BaseController {
    static private final Logger logger = LoggerFactory.getLogger(SellerController.class);

    @RequestMapping("/public")
    public ModelAndView publicItem(HttpServletRequest request, HttpServletResponse response) {
        ModelAndView mav = genModelAndView("/tmpl/public");

        UserVO userVO = LoginUtils.loginCheck(request);

        logger.info("[op:publicItem] userVO={}", JSON.toJSONString(userVO));

        if (userVO.getLoginType() != LoginType.SELLER.getValue()) {
            logger.error("[op:publicItem] no auth, userVO={}", JSON.toJSONString(userVO));
            throw new CommonServiceException("没有权限发布商品，请登录卖家账号");
        }
        mav.addObject("user", userVO);
        return mav;
    }
}
